package com.dkm.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})//json解析忽略为空的对象属性
@Entity
@Table(name = "users")
public class Users {

	@Id
	private String user_id;
	private String login_name;
	private String password;
	
	private String head_portrait;
	private String is_lockout;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date last_login_time;
	private Integer password_wrong_num;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date lock_time;
	private String protect_email;
	private String protect_phone;
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date create_time;
	
	//用户和部门多对一关系
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "department_id")
	private Department department;
	
	//用户和角色多对多关系
	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(
			name = "user_role",
			joinColumns = {@JoinColumn(name="user_id")},
			inverseJoinColumns = {@JoinColumn(name="role_id")}
	)
	private List<Role> roles;
	
	//消息集合
	@Transient//表示该属性并非一个到数据库表的字段的映射， ORM 框架将忽略该属性
	private List<Message> messages;
	
	public String getHead_portrait() {
		return head_portrait;
	}
	public void setHead_portrait(String head_portrait) {
		this.head_portrait = head_portrait;
	}
	public List<Message> getMessages() {
		return messages;
	}
	public void setMessages(List<Message> messages) {
		this.messages = messages;
	}
	
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public Department getDepartment() {
		return department;
	}
	public void setDepartment(Department department) {
		this.department = department;
	}
	public Users() {
		super();
		// TODO Auto-generated constructor stub
	}
	public Users(String user_id, String login_name, String password, String is_lockout, Date last_login_time,
			Integer password_wrong_num, Date lock_time, String protect_email, String protect_phone,
			Date create_time) {
		super();
		this.user_id = user_id;
		this.login_name = login_name;
		this.password = password;
		this.is_lockout = is_lockout;
		this.last_login_time = last_login_time;
		this.password_wrong_num = password_wrong_num;
		this.lock_time = lock_time;
		this.protect_email = protect_email;
		this.protect_phone = protect_phone;
		this.create_time = create_time;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String user_id) {
		this.user_id = user_id;
	}
	public String getLogin_name() {
		return login_name;
	}
	public void setLogin_name(String login_name) {
		this.login_name = login_name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getIs_lockout() {
		return is_lockout;
	}
	public void setIs_lockout(String is_lockout) {
		this.is_lockout = is_lockout;
	}
	public Date getLast_login_time() {
		return last_login_time;
	}
	public void setLast_login_time(Date last_login_time) {
		this.last_login_time = last_login_time;
	}
	public Integer getPassword_wrong_num() {
		return password_wrong_num;
	}
	public void setPassword_wrong_num(Integer password_wrong_num) {
		this.password_wrong_num = password_wrong_num;
	}
	public Date getLock_time() {
		return lock_time;
	}
	public void setLock_time(Date lock_time) {
		this.lock_time = lock_time;
	}
	public String getProtect_email() {
		return protect_email;
	}
	public void setProtect_email(String protect_email) {
		this.protect_email = protect_email;
	}
	public String getProtect_phone() {
		return protect_phone;
	}
	public void setProtect_phone(String protect_phone) {
		this.protect_phone = protect_phone;
	}
	public Date getCreate_time() {
		return create_time;
	}
	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	}
	@Override
	public String toString() {
		return "Users [user_id=" + user_id + ", login_name=" + login_name + ", password=" + password + ", is_lockout="
				+ is_lockout + ", last_login_time=" + last_login_time + ", password_wrong_num=" + password_wrong_num
				+ ", lock_time=" + lock_time + ", protect_email=" + protect_email + ", protect_phone=" + protect_phone
				+ ", create_time=" + create_time + "]";
	}
	
}
